<?php
namespace Model;
use Think\Model;
class CatModel extends Model{
	//写一个构造方法，调用父类构造方法
	protected $cats = [];
	public function  __construct(){
		parent::__construct();
		$this->cats = $this->select();
	} 	

	public function getTree($parent_id = 0,$lev = 0){
		$tree = [];
		foreach($this->cats as $v){
			if($v['parent_id'] == $parent_id){
				$v['lev'] = $lev;
				$tree[] = $v;

				$tree = array_merge($tree,$this->getTree($v['cat_id'],$lev+1));
			}
		}
		return $tree;
	}
} 